package com.billdowney.controller;

import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.billdowney.entity.user.UserLoginInfo;
import com.billdowney.service.util.user.UserUtil;

/**
 * @ClassName: BaseController
 * @Description: 基础控制器类
 * @author 超级小富翁 - BillDowney
 * @date 2018年4月2日 下午3:33:11
 */
public class BaseController {

	@Autowired
	protected HttpServletRequest request;

	@Autowired
	protected HttpServletResponse response;

	@Autowired
	protected HttpSession session;

	/**
	 * @Function: initBinder
	 * @Description: 解决前台传Date类型时转换错误问题
	 * @param request
	 * @param binder
	 * @throws Exception
	 * @author: 超级小富翁 - BillDowney
	 * @date: 2018年3月29日 下午10:28:30
	 */
	@InitBinder
	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
		CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true);// true表示允许为空，false反之
		binder.registerCustomEditor(Date.class, dateEditor);
		CustomDateEditor timeEditor = new CustomDateEditor(new SimpleDateFormat("HH:mm:ss"), true);// true表示允许为空，false反之
		binder.registerCustomEditor(Time.class, timeEditor);
		CustomDateEditor sqlDateEditor = new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true);// true表示允许为空，false反之
		binder.registerCustomEditor(java.sql.Date.class, sqlDateEditor);
	}

	/**
	 * 获取登录的用户信息
	 * 
	 * @return
	 * @author: 超级小富翁 - BillDowney
	 * @date: 2019年2月10日 下午5:42:49
	 */
	public UserLoginInfo getUserLoginInfo() {
		return UserUtil.getSecurityUser();
	}
}
